import { getlist } from "@/api/system-setup/building";
import { varietyList ,leaveCause,} from "../constant/constant.js";
import cloneDeep from "lodash/cloneDeep";
export const mixins = {
  data() {
    return {
      userId: null,
      total: 0,
      entryDialog: false,
      transferDialog: false,
      leaveDialog: false,
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now() - 8.64e6;
        },
      },
      buildList: [],
      columnList1: [],
      searchBuildList: [],
      defaultEntryForm: {},
      defaultTransferForm: {},
      defaultLeaveForm: {},
      varietyList,
      columnList: [],
      leaveCause
    };
  },
  created() {
    this.getBulidList();
    this.defaultEntryForm = cloneDeep(this.entryForm);
    this.defaultTransferForm = cloneDeep(this.transferForm);
    this.defaultLeaveForm = cloneDeep(this.leaveForm);
    this.userId = sessionStorage.getItem("id");
  },
  methods: {
    //栋宿下拉列表
    async getBulidList() {
      let data = {
        buildingsType: "",
        columnMaxNumber: 0,
        sumColumnNumber: 0,
        name: "",
        pageNum: 0,
        pageSize: 10,
        remark: "",
      };
      let res = await getlist(data);
      if (res.code == 200) {
        this.buildList = res.buildingsList.records;
        this.searchBuildList = cloneDeep(this.buildList);
      }
    },
    entry() {
      this.columnList = [];
      this.entryForm = cloneDeep(this.defaultEntryForm);
      this.transferForm = cloneDeep(this.defaultTransferForm);
      this.$nextTick(() => {
        this.$refs.entryForm.clearValidate();
      });
      this.entryDialog = true;
    },
    transfer() {
      this.columnList = [];
      this.entryForm.buildingsId = null;
      this.transferForm = cloneDeep(this.defaultTransferForm);
      this.$nextTick(() => {
        this.$refs.transferForm.clearValidate();
      });
      this.transferDialog = true;
    },
    leave() {
      this.columnList = [];
      this.leaveHerdsPigsCode = []
      this.leaveForm = cloneDeep(this.defaultLeaveForm);
      this.$nextTick(() => {
        this.$refs.leaveForm.clearValidate();
      });
      this.leaveDialog = true;
    },
  },
};
